package indi.zhifa.recipe.bailan.framework.auth.impl.dao.service;
import com.alibaba.fastjson2.JSONObject;
import indi.zhifa.recipe.bailan.framework.auth.impl.entity.po.AuthNodeEntity;
import indi.zhifa.recipe.bailan.framework.auth.impl.entity.po.DomainEntity;
import indi.zhifa.recipe.bailan.framework.auth.impl.entity.po.RelUserAuthEntity;
import indi.zhifa.recipe.bailan.framework.auth.dao.IBaseAuthNodeRelevantDao;
import indi.zhifa.recipe.bailan.framework.auth.entity.po.BaseAuthNodeEntity;
import indi.zhifa.recipe.bailan.framework.auth.entity.po.BaseDomainEntity;
import indi.zhifa.recipe.bailan.framework.auth.entity.po.BaseRelUserAuthEntity;
import indi.zhifa.recipe.bailan.framework.common.entity.exception.ServiceException;

import java.util.List;

public interface IAuthNodeRelevantDao extends IBaseAuthNodeRelevantDao {
    DomainEntity domain_generate();
    DomainEntity domain_load(JSONObject pCfg);
    DomainEntity domain_check(Long pId);
    Long domain_findByCode(String pCode);
    default DomainEntity domain_check(String pCode){
        Long id = domain_findByCode(pCode);
        if(null == id){
            throw new ServiceException("没有找到名为"+pCode+"的领域");
        }
        return domain_check(id);
    }
    default boolean domain_existByCode(String pCode){
        Long id = domain_findByCode(pCode);
        return null != id;
    }

    List<BaseDomainEntity> domain_list();


    DomainEntity authNode_save(BaseDomainEntity pBaseDomainEntity);

    AuthNodeEntity authNode_generate();
    AuthNodeEntity authNode_load(JSONObject pCfg);

    Long authNode_findByDomainAndCode(Long pDomainId, String pCode);
    AuthNodeEntity authNode_check(Long pId);
    default AuthNodeEntity authNode_check(Long pDomainId, String pCode){
        Long id = authNode_findByDomainAndCode(pDomainId,pCode);
        if(null == id){
            throw new ServiceException(pDomainId + "下没有找到名为"+pCode+"的部门");
        }
        return authNode_check(id);
    }

    AuthNodeEntity authNode_save(BaseAuthNodeEntity pBaseAuthNodeEntity);
    AuthNodeEntity authNode_update(Long pId, BaseAuthNodeEntity pBaseAuthNodeEntity);

    List<BaseAuthNodeEntity> authNode_listByDomainId(Long pDomainId);
    List<BaseAuthNodeEntity> authNode_listByParentId(Long pParentId);
    List<BaseAuthNodeEntity> authNode_listDescendants(String pCascade);
    AuthNodeEntity authNode_delete(Long pId);


    RelUserAuthEntity relUserAuth_generate();

    List<BaseRelUserAuthEntity> relUserAuth_listByUserId(Long pId);
    List<BaseRelUserAuthEntity> relUserAuth_saveBatch(Long pUserId, List<BaseRelUserAuthEntity> pBaseRelUserAuthEntityList);
    void relUserAuth_deleteByUserId(Long pUserId);
}
